package com.auxgroup.hr.front.service.personnal.impl;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;

import com.auxgroup.hr.front.commons.utils.DateUtils;
import com.auxgroup.hr.front.dao.domain.PsCEmpAbsentVwPrimary;
import com.auxgroup.hr.front.dao.domain.PsCEmpMatchVw;
import com.auxgroup.hr.front.dao.domain.PsCEmplCrdVw;
import com.auxgroup.hr.front.dao.domain.PsCLaveDtlVw;
import com.auxgroup.hr.front.dao.repository.PsCEmpMatchVwRepository;
import com.auxgroup.hr.front.dao.repository.PsCEmplCrdVwRepository;
import com.auxgroup.hr.front.dao.repository.PsCLaveDtlVwRepository;
import com.auxgroup.hr.front.service.personnal.DailyCalendarService;

/** 
 * @author lvliuhao 
 * @version 创建时间：2018年8月16日 下午3:00:43 
 * 类说明 
 */
@Service("dailyCalendarService")
public class DailyCalendarServiceImpl implements DailyCalendarService {

	@Autowired
	private PsCEmpMatchVwRepository psCEmpMatchVwRepository;
	
	@Autowired
	private PsCLaveDtlVwRepository psCLaveDtlVwRepository;
	
	@Autowired
	private PsCEmplCrdVwRepository psCEmplCrdVwRepository;

	@Override
	public List<PsCEmpMatchVw> getEmpMatchs(String emplid,String dateMonth) {
		return psCEmpMatchVwRepository.queryMatchsByDateMonth(emplid, dateMonth);
	}
	
	@Override
	public PsCEmpMatchVw getEmpMatch(String emplid, Date dateDay) {
		PsCEmpAbsentVwPrimary primary = new PsCEmpAbsentVwPrimary();
		primary.setEmplid(emplid);
		primary.setEmplRcd(new BigDecimal(0));
		primary.setDateDay(dateDay);
		return psCEmpMatchVwRepository.findOne(primary);
	}


	@Override
	public List<PsCLaveDtlVw> getLaveDtlsByMonth(String emplid,String dateMonth) {
		return psCLaveDtlVwRepository.queryLaveDtlsByDateMonth(emplid,dateMonth);
	}
	
	@Override
	public List<PsCLaveDtlVw> getLaveDtlsByDay(String emplid, String dateDay) {
		PsCLaveDtlVw query = new PsCLaveDtlVw();
		query.setEmplid(emplid);
		query.setEmplRcd(new BigDecimal(0));
		query.setDateDay(DateUtils.parseDate(dateDay, DateUtils.FORMAT_DEFAULT));
		return psCLaveDtlVwRepository.findAll(Example.of(query));
	}

	@Override
	public List<PsCEmplCrdVw> getEmplCrds(String emplid,Date dateDay) {
		PsCEmplCrdVw query = new PsCEmplCrdVw();
		query.setEmplid(emplid);
		query.setEmplRcd(new BigDecimal(0));
		query.setDateDay(dateDay);
		return psCEmplCrdVwRepository.findAll(Example.of(query),new Sort(Direction.ASC,"cCardTime"));
	}
}
 